package com.twu.biblioteca;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class MainMenu {
    public void Menu (){
        int Choice;
        Book Library[] = new Book[10];
        Movie VidLib[] = new Movie[15];
        User UserList[]= new User[10];
        ListofBooks PopClass=new ListofBooks();
        ReserveBook ReserveClass=new ReserveBook();
        ListMovie MovClass=new ListMovie();
        ListofUsers UserClass=new ListofUsers();
        int NMov=MovClass.PopulateMovieList(VidLib);
        int NBooks=PopClass.PopulateList(Library);
        int NUser=UserClass.PopulateUser(UserList);
        int Loggedin=0;
        String Username=new String();
        String password=new String();
        try{

            BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
            do {
                System.out.println("Biblioteca Main Menu\n1.List of all books in the library\n2.Reserve a book");
                System.out.println("3.Check Membership Details\n4.List Movies\n5.User\n6.Exit Biblioteca\nChoose a Menu option - ");
                String s = bufferRead.readLine();

            Choice=Integer.parseInt(s);
            if (Choice==1){
                PopClass.Booklist(Library,NBooks);
            }
            else if (Choice==2){
                if (Loggedin==1)
                ReserveClass.Reserve(Library,NBooks);
                else
                    System.out.println("You must be logged in to reserve a book");
            }
            else if (Choice==3){
                 if(Loggedin==0)
                Membership.Message();
                else
                     Membership.ShowDetails(Username,UserList,NUser);
            }
            else if (Choice==4){
                 ListMovie.Displaylist(VidLib,NMov);
            }
            else if (Choice==5){
                 System.out.print("Enter Username - ");
                Username=bufferRead.readLine();
                System.out.print("Enter Password - ");
                password=bufferRead.readLine();
                Loggedin=Membership.Login(Username,password,UserList,NUser);
                if (Loggedin==0)
                    System.out.println("Incorrect Username or password");
                else
                    System.out.println("Login Successful");
            }
            else if (Choice==6);
            else System.out.println("Select a valid option!!");
            }while (Choice!=6);
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }
}
